#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>


#define BUFFERSIZE 1024

int main(int argc,char **argv)
{
  int fileOne,fileTwo,number;
  char buffer[BUFFERSIZE];

  if(argc != 3)
    {
      printf("Usage: copy from to\n");
      exit(1);
    }

  if((fileOne = open(argv[1],O_RDONLY,0)) ==  -1)
    {
      printf("copy: can't open %s",argv[1]);
      exit(1);
    }

  
  if((fileTwo = creat(argv[2],O_WRONLY)) ==  -1) 
    {
      printf("copy: can't create %s,mode %03o",argv[2],O_WRONLY);
      exit(1);
    }

  while((number = read(fileOne,buffer,BUFFERSIZE))>0)
    {
      if(write(fileTwo,buffer,number) != number)
        {
          printf("copy: write error on file %s",argv[2]);
          exit(1);
        }
    }
  return 0;
}
